package com.estate.web.controller.report.report;

import com.estate.common.core.controller.BaseController;
import com.estate.common.core.domain.AjaxResult;
import com.estate.common.utils.DateUtils;
import com.estate.report.service.IDataStatisticsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/report")
public class LeaderController extends BaseController {

    @Resource
    IDataStatisticsService dataStatisticsService;

    @PostMapping("/gen")
    public AjaxResult gen() {
        Date today = DateUtils.getNowDate();
        Date before = DateUtils.addDays(today, -365);
        dataStatisticsService.genStatisticsData(before, today);
        return success();
    }

    @GetMapping("/{type}")
    public AjaxResult getReportData(@PathVariable String type) {
        return success(dataStatisticsService.getStatisticsData(type));
    }

}
